﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Threading;

namespace WeiTalk.Controls
{
    public partial class PeopleControl : UserControl
    {
        const string FollowCountMsg = "关注数: ";
        const string LocationMsg = "所在地: ";
        const string FriendsCountMsg = "关注数: ";
        const string StatusesCountMsg = "微博数: ";
        const string CreateAtMsg = "注册时间: ";
        const string FollowMeMsg = "互粉: ";
        const string FollowsCountMsg = "粉丝数: ";

        public PeopleControl()
        {
            InitializeComponent();
        }

        #region Properties

        public string Id
        {
            get;
            set;
        }

        public bool OnLineStatus
        {
            set {
                if (value)
                {
                    spOnLineStatus.Background = new SolidColorBrush(Colors.Green);
                }
                else
                {
                    spOnLineStatus.Background = new SolidColorBrush(Colors.Gray);
                }
                //在线状态暂时官方不支持
                spOnLineStatus.Visibility = System.Windows.Visibility.Collapsed;
            }
        }

        public Color GBColor
        {
            set
            {
                LayoutRoot.Background = new SolidColorBrush(value);
            }
        }

        public new string Name
        {
            get;
            set;
        }

        public string ScreenName
        { get; set; }


        public string CreateAt
        {
            get
            {
                return tbCreateAt.Text;
            }
            set
            {
                tbCreateAt.Text =CreateAtMsg + value;
            }
        }

        public bool FollowMe
        {
            get
            {
                return tbFollowMe.Text.Equals("Yes");
            }
            set
            {
                tbFollowMe.Text = value ? FollowMeMsg + "Yes" :FollowMeMsg + "No";
            }
        }

        public string Descriotion
        {
            get
            {
                return tbDescription.Text;
            }
            set
            {
                tbDescription.Text = value;
            }
        } 
        #endregion

        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            if (!String.IsNullOrEmpty(Name))
            {
                if (!Name.Equals(ScreenName))
                {
                    tbName.Text = String.Format("{0} ({1})", Name, ScreenName);
                }
                else
                {
                    tbName.Text = Name;
                }
            }
            else
            {
                tbName.Text = "Unknow";
            }
            Thread.Sleep(10);
            Random random = new Random(DateTime.Now.Millisecond);
            sbLastStatus.AutoReverse = true;
            sbLastStatus.Completed += (s, ev) => {
                Thread.Sleep(10);
                random = new Random(DateTime.Now.Millisecond);
                sbLastStatus.BeginTime = new TimeSpan(0, 0, 0, random.Next(1, 5), 0);
                sbLastStatus.Begin();
            };
            if (!String.IsNullOrEmpty(Descriotion))
            {
                sbLastStatus.BeginTime = new TimeSpan(0, 0, 0, random.Next(1, 5), 0);
                sbLastStatus.Begin();
            }
            else
            {
                stackPanel.Visibility = System.Windows.Visibility.Collapsed;
            }
        }
    }
}
